Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define_aggregate: provide empty user-defined constructor or destructor for unions with non-trivial members #119

Open
wants to merge 10 commits into
base: p2996
Choose a base branch
from

Conversation

BaLiKfromUA
Copy link

@BaLiKfromUA BaLiKfromUA commented Nov 23, 2024

Issue number of the reported bug or feature request: #115

Describe your changes

Tried to implement next behaviour from paper:

[7.10] If C is a union type for which any of its members are not trivially default constructible, then D has a user-provided default constructor which has no effect.

[7.11] If C is a union type for which any of its members are not trivially destructible, then D has a user-provided destructor which has no effect.  

Testing performed

  • Automated testing with type_traits
  • Manual testing via code like this
union UU;
static_assert(is_type(define_aggregate(
    ^^UU,
    {
        data_member_spec(^^int),
        data_member_spec(^^std::string),
    })));

int main() {
  UU u;
  u.~UU();
  
  return 0;
}
  • assertations in code

Additional context

N/A

Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
NewDecl->needsImplicitDefaultConstructor();

if (NeedToGenerateDefaultConstr) {
S.DeclareImplicitDefaultConstructor(NewDecl);
Copy link
Author

@BaLiKfromUA BaLiKfromUA Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potentially hacky approach but I tried to reuse existing code as much as possible to not copy generation of constructors

@@ -4532,6 +4532,47 @@ bool define_aggregate(APValue &Result, ASTContext &C, MetaActions &Meta,
if (!Definition)
return true;

if (Definition->isUnion()) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided to put this logic here instead of SemaReflect because this code is specific to function and doesn't require access to Sema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant